<?php

declare(strict_types=1);

namespace App\Model;



/**
 * @property int $id 
 * @property int $userid 
 * @property int $to_userid 
 * @property string $message 
 * @property int $status 0-等待处理 1-通过 2-拒绝
 * @property int $is_del 是否删除
 * @property int $apply_time 
 * @property int $audit_time 
 * @property int $del_time 删除时间
 * @property-read null|User $user 
 * @property-read null|User $toUser 
 */
class ImApply extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'im_apply';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'to_userid', 'message', 'status', 'is_del', 'apply_time', 'audit_time', 'del_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'to_userid' => 'integer', 'status' => 'integer', 'is_del' => 'integer', 'apply_time' => 'integer', 'audit_time' => 'integer', 'del_time' => 'integer'];

    public function user(){
        return $this->hasOne(User::class, 'id', 'userid')->select(['id', 'nickname', 'avatar', 'role_id']);
    }

    public function toUser(){
        return $this->hasOne(User::class, 'id', 'to_userid')->select(['id', 'nickname', 'avatar', 'role_id']);
    }
}
